package com.basker.pisces.domain.entity.event;

import java.util.EventObject;

import org.springframework.util.Assert;

import com.basker.pisces.domain.entity.data.IDataEntity;
import com.basker.pisces.domain.entity.meta.Entity;

/**
 * 数据实体的事件抽象类
 *
 * @author hangwen
 */
public abstract class AbstractDataEntityEventObject extends EventObject {

    private static final long serialVersionUID = 665733712276141548L;

    private IDataEntity dataEntity;

    public AbstractDataEntityEventObject(Object source) {
        super(source);

        if (source instanceof IDataEntity) {
            this.dataEntity = (IDataEntity) source;
        }

    }

    public IDataEntity getDataEntity() {
        Assert.notNull(dataEntity, "'dataEntity' is required");
        return dataEntity;
    }

    public Object getDataObject() {
        return this.getDataEntity().getDataObject();
    }

    public Entity getRootEntity() {
        return this.getDataEntity().getEntity();
    }

    public void setDataEntity(IDataEntity dataEntity) {
        this.dataEntity = dataEntity;
    }

}
